package Cau2;

import java.io.BufferedReader;
import java.io.DataOutputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.Socket;
import java.net.UnknownHostException;

public class TCPClient {
	Socket sk;
	public void run() throws IOException
	{
		
		String strUser;
		String strServer;
		System.out.println("Client dang chay....");
		while(true)
		{
			sk=new Socket("localhost",1234);
			System.out.println("Nhap thong so: ");
			//Láº¥y dá»¯ liá»‡u nháº­p tá»« bÃ n phÃ­m
			BufferedReader in=new BufferedReader(new InputStreamReader(System.in));
			if(in.equals("+THOAT"))
				break;
			//Gá»­i dá»¯ liá»‡u tá»›i server
			DataOutputStream outToserver=new DataOutputStream(sk.getOutputStream());
			//Nháº­n dá»¯ liá»‡u tá»« server gá»­i vá»�
			BufferedReader inFromserver=new BufferedReader(new InputStreamReader(sk.getInputStream()));
			
			strUser=in.readLine();
			outToserver.writeBytes(strUser+ '\n');
			
			
			strServer=inFromserver.readLine();
			System.out.println(strServer);
		}
		
		System.out.println("Client ket thuc.......");
		sk.close();
		
	}
	public static void main(String[] args) throws UnknownHostException, IOException {
		TCPClient client=new TCPClient();
		client.run();
	}
}
